package org.example.session;

import lombok.Getter;
import org.example.executor.parameter.ParameterHandler;
import org.example.executor.result.ResultContext;
import org.example.mapping.BoundSql;
import org.example.reflection.ObjectFactory;
import org.example.reflection.ReflectorFactory;
import org.example.type.TypeHandlerRegistry;

import java.sql.ResultSet;
import java.util.List;

@Getter
public class DefaultResultHandler implements ResultHandler<Object> {
    private final ObjectFactory objectFactory;

    private final List<Object> resultList;

    public DefaultResultHandler(ObjectFactory objectFactory) {
        this.objectFactory = objectFactory;
        this.resultList = objectFactory.create(List.class);
    }

    @Override
    public void handleResult(ResultContext<?> resultContext) {
        resultList.add(resultContext.getResultObject());
    }

    public void handleResultSets(ResultSet resultSet, ParameterHandler parameterHandler, ResultHandler<?> resultHandler, BoundSql boundSql, TypeHandlerRegistry typeHandlerRegistry, ReflectorFactory reflectorFactory, ResultSet resultSet1, RowBounds rowBounds) {
        try {
            while (resultSet.next()) {
                //resultHandler.handleResult(resultSet);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
